package com.utils.httphelper;

import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;

import javax.annotation.Resource;

/**
 * 展业推数时将处于拒绝状态的单子置为结束
 * 
 * 首先读取url,然后调用servlet
 * @author zhaozongyi
 * @date 2016-4-25
 */
// @Component("mobile.RefuseToEndForAPPServlet")
public class RefuseToEndForAPP {

	private static final String SERVLETURL;

	@Resource(name = "pc.conServletUtil")
	ConServletUtil conSercletUtil;

	// 静态块的作用是从属性文件中读取url
	static {
		Properties props = new Properties();
		String fileName = "sunshineserver.properties";
		InputStream in = RefuseToEndForAPP.class.getClassLoader().getResourceAsStream(fileName);
		if (in != null) {
			try {
				props.load(in);
				SERVLETURL = props.getProperty("sunshine.url") + props.getProperty("sunshine.refuseToEndForAPPServlet");
			} catch (IOException e) {
				throw new RuntimeException("读取接口工程地址文件失败，请确认classpath下存在sunshineserver.properties," + e.getMessage(),
						e);
			} finally {
				if (in != null) {
					try {
						in.close();
					} catch (IOException e) {
					}
				}
			}

		} else {
			SERVLETURL = "";
		}
	}

	public void refuseToEndForAPP(String parameter) throws Exception {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("methodName", "refuseToEndForAPP");
		map.put("parameter", parameter);

		// 调用Sunshine工程servlet 拒绝节点结束流程
		Map<String, Object> resultMap = conSercletUtil.applyOtherProjectServlet(map, SERVLETURL);

		if (resultMap != null && !resultMap.isEmpty()) {
			
			Boolean isSucc = (Boolean) resultMap.get("flag");
			
			System.out.print("移动展业APP推数时，拒绝节点结束流程任务是否成功：【" + isSucc.toString() + "】");
		}
	}

}